package com.zz.inventory.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.zz.inventory.domain.Users;
import com.zz.inventory.service.IUsersService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 学校端用户Controller
 * 
 * @author zz
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/users")
public class UsersController extends BaseController
{
    @Autowired
    private IUsersService usersService;

    /**
     * 查询学校端用户列表
     */
    @RequiresPermissions("schoolmanage:users:list")
    @GetMapping("/list")
    public TableDataInfo list(Users users)
    {
        startPage();
        List<Users> list = usersService.selectUsersList(users);
        return getDataTable(list);
    }

    /**
     * 导出学校端用户列表
     */
    @RequiresPermissions("schoolmanage:users:export")
    @Log(title = "学校端用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Users users)
    {
        List<Users> list = usersService.selectUsersList(users);
        ExcelUtil<Users> util = new ExcelUtil<Users>(Users.class);
        util.exportExcel(response, list, "学校端用户数据");
    }

    /**
     * 获取学校端用户详细信息
     */
    @RequiresPermissions("schoolmanage:users:query")
    @GetMapping(value = "/{schoolUserId}")
    public AjaxResult getInfo(@PathVariable("schoolUserId") Long schoolUserId)
    {
        return success(usersService.selectUsersBySchoolUserId(schoolUserId));
    }

    /**
     * 新增学校端用户
     */
    @RequiresPermissions("schoolmanage:users:add")
    @Log(title = "学校端用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Users users)
    {
        return toAjax(usersService.insertUsers(users));
    }

    /**
     * 修改学校端用户
     */
    @RequiresPermissions("schoolmanage:users:edit")
    @Log(title = "学校端用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Users users)
    {
        return toAjax(usersService.updateUsers(users));
    }

    /**
     * 删除学校端用户
     */
    @RequiresPermissions("schoolmanage:users:remove")
    @Log(title = "学校端用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{schoolUserIds}")
    public AjaxResult remove(@PathVariable Long[] schoolUserIds)
    {
        return toAjax(usersService.deleteUsersBySchoolUserIds(schoolUserIds));
    }
}
